//
//  CollectionViewVC.swift
//  Swift_Study
//
//  Created by apple on 2018/9/27.
//  Copyright © 2018年 dminfo. All rights reserved.
//

import UIKit

class CollectionViewVC: UIViewController {
  var backImg  = UIImageView.init(frame:   CGRect(x: 0, y: 0, width: kSize.width, height: kSize.height))
  var collectionView : UICollectionView?
  let cellID = "CollectionViewCellId"
  fileprivate var interests = Interest.createInterests()
  
  override func viewDidLoad() {
        super.viewDidLoad()
    
       makeInterface()
  
  
  
  }
    
//  初始化界面
  func makeInterface(){
     view.backgroundColor = UIColor.white
     title = "CollectionView"
     backImg.image = UIImage.init(named: "blue")
     view.addSubview(backImg)
    
    //collectionView
      let layout = UICollectionViewFlowLayout()
      layout.itemSize = CGSize(width:kSize.width - 60,height:kSize.height - 200)
    
      layout.scrollDirection = .horizontal
      layout.minimumLineSpacing = 0
      layout.minimumInteritemSpacing = 0
    
    collectionView = UICollectionView.init(frame:CGRect(x: 30, y: 100, width: kSize.width - 60, height: kSize.height - 200)
, collectionViewLayout: layout)
    collectionView?.isPagingEnabled = true
    collectionView?.backgroundColor = UIColor.clear
    collectionView!.register(UINib(nibName:"CollectionViewCell",bundle:nil), forCellWithReuseIdentifier: cellID)
    collectionView!.delegate = self
    collectionView!.dataSource = self
    
    view.addSubview(collectionView!)
  }
  
}
// MARK:- collection-delegate/datasource
extension CollectionViewVC:UICollectionViewDelegate,UICollectionViewDataSource {
  func numberOfSections(in collectionView: UICollectionView) -> Int {
    return 1
  }
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return interests.count
  }
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell:CollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath) as! CollectionViewCell
    cell.interest = self.interests[indexPath.row]
      return cell
  }
  
}



